package com.ibk.system.login;

import com.ibk.system.R;
import com.ibk.system.R.id;
import com.ibk.system.R.layout;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class PopViewActivity extends Activity implements OnClickListener {
	public boolean popViewVisible;
	public RelativeLayout popViewLayout;
	public PopViewLayout popView;
	public Button button;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.popup);

		popViewVisible = false;
		popViewLayout = (RelativeLayout) findViewById(R.id.popViewLayout);
		popViewLayout.setOnClickListener(this);
		// button = (Button) findViewById(R.id.popup);
		// button.setTag("popView");
		// button.setOnClickListener(this);

		popView = new PopViewLayout(getApplicationContext(), this);
		popView.setVisibility(View.INVISIBLE);

		Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
				.getDefaultDisplay();
		popView.setPosition(display);
		// this.addContentView(popView, new LayoutParams(
		// display.getWidth() / 3 * 2, display.getHeight() / 2));

		this.addContentView(popView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
	}

	public void nextPage(String resultCode) {
		if (resultCode.equals("success")) {
			Intent it = new Intent(getApplicationContext(), LoginResultActivity.class);
			it.putExtra("result", resultCode);
			startActivity(it);
		} else {
			Toast.makeText(getApplicationContext(), "Login Fail",
					Toast.LENGTH_SHORT).show();
			popView.setVisibility(View.INVISIBLE);
		}
	}

	public void onClick(View v) {
		if (popViewVisible) {
			popView.setVisibility(View.INVISIBLE);
		} else {
			popView.clearComponent();
			popView.setVisibility(View.VISIBLE);
		}
		popViewVisible = !popViewVisible;
		// if ("popView".equals(v.getTag())) {
		// // 踰꾪듉���대┃�섎㈃ �앸럭瑜�visible �쒗궓��
		// popView.clearComponent();
		// popView.setVisibility(View.VISIBLE);
		// }
	}
}
